{extend name="public/admin_base"}
{block name="main"}
<div class="layui-tab layui-tab-brief" lay-filter="demoTitle">
    <ul class="layui-tab-title site-demo-title">
        <li class="layui-this">分类列表</li>
    </ul>
    <div class="layui-body layui-tab-content site-demo site-demo-body">
        <div class="layui-tab-item layui-show">
            <div class="layui-main">
                <div id="LAY_preview">
                    <form class="layui-form">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <select name="pid" lay-filter="pid">
                                        <option value="">请选择问题</option>
                                        <option value="0" {eq name="cid" value="0"} selected {/eq}>全部</option>
                                        {volist name="category" id="vo"}
                                        <optgroup label="{$vo.name}">
                                            {volist name="vo.childrens" id="v"}
                                            <option value="{$v.id}" {eq name="cid" value="$v.id"} selected {/eq}>{$v.name}</option>
                                            {/volist}
                                        </optgroup>
                                        {/volist}
                                    </select>
                                </div>
                            </div>
                        </div>
                    </form>
                    <button data-method="setTop" class="layui-btn open_layer" data-href='{:url("save_api")}'>添加接口</button>
                    <table class="layui-table" lay-even="" lay-skin="nob" id="data_list">
                    </table>
                </div>
                <div id="demo1">
                </div>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="javascript"}
<script>
    layui.use(['laypage', 'layer', 'form'], function() {
        var laypage = layui.laypage, $ = layui.jquery, form = layui.form()
                , layer = layui.layer;

        laypage({
            cont: 'demo1'
            , pages: '{php}echo ceil($data["total"] / $data["per_page"]);{/php}' //总页数
            , skip: true //连续显示分页数
        });

        form.on('select(pid)', function(data){
            window.location.href = '/api/document/api_list/cid/' + data.value;
        });

        $(document).on('click', '.delete', function () {
            var _this = $(this);
            layer.confirm('确定删除?', {icon: 3, title:'提示'}, function(index){
                var id = _this.data('id');
                $.get("{:url('delete_data')}", {id : id, model : 'api_returns'}, function (msg) {
                    if (msg.code == 200) {
                        layer.alert('删除成功', {icon: 1}, function (index) {
                            _this.parents('tr').slideUp().remove();
                            layer.close(index);
                        });
                    } else {
                        layer.alert(msg.msg, {icon: 2});
                    }
                });
            });
        });

        get_list(0);
    });
</script>
{/block}